package com.jt.tenant.widget;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CircleOptions;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MarkerOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.amap.api.services.geocoder.GeocodeResult;
import com.amap.api.services.geocoder.GeocodeSearch;
import com.amap.api.services.geocoder.RegeocodeResult;
import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;

public class JTMapView extends MapView {

    private AMap aMap;

    public JTMapView(Context context, AttributeSet attributeSet) {

        super(context, attributeSet);

        MyLocationStyle myLocationStyle = new MyLocationStyle();

        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromView(JTApplication.ScaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(context).inflate(R.layout.map_location, null))));

        myLocationStyle.strokeColor(Color.BLACK);

        myLocationStyle.strokeWidth(5);

        aMap = getMap();

        aMap.setMyLocationStyle(myLocationStyle);

        aMap.setOnMapLongClickListener(new AMap.OnMapLongClickListener() {

            @Override
            public void onMapLongClick(LatLng latLng) {

                aMap.clear();

                aMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromView(JTApplication.ScaleScreenHelper.loadView((ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.map_location, null)))));

                aMap.addCircle(new CircleOptions().center(latLng).radius(1000).strokeColor(Color.parseColor("#501873f8")).fillColor(Color.parseColor("#501592ff")).strokeWidth(2));

                GeocodeSearch geocoderSearch = new GeocodeSearch(getContext());

                geocoderSearch.setOnGeocodeSearchListener(new GeocodeSearch.OnGeocodeSearchListener() {
                    @Override
                    public void onRegeocodeSearched(RegeocodeResult regeocodeResult, int i) {

                    }

                    @Override
                    public void onGeocodeSearched(GeocodeResult geocodeResult, int i) {

                    }

                });


                //latLonPoint参数表示一个Latlng，第二参数表示范围多少米，GeocodeSearch.AMAP表示是国测局坐标系还是GPS原生坐标系
//                RegeocodeQuery query = new RegeocodeQuery(latLonPoint, 200,GeocodeSearch.AMAP);

//                geocoderSearch.getFromLocationAsyn(query);

            }

        });

    }

}
